
INS_DIR	:= ../../bin/

CFLAGS 		+= -Wall -fPIC -Werror -g -w -DDEBUG=1 -fmessage-length=0 -O2
CFLAGS		+= -I../include

CXXFLAGS	= $(CFLAGS)

LDFLAGS		+= -Wl,--as-needed

SRCS := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SRCS))

ifneq ($(strip $(TOOLS_BUILD_SHARED)),)
TARGET	:= libmincrypt.so
LDFLAGS	+= -Wl,-rpath=.:./bin
else
TARGET	:= libmincrypt.a
endif

all:$(TARGET)
	
$(TARGET):$(OBJS)
ifneq ($(strip $(TOOLS_BUILD_SHARED)),)
	$(CC) -o $@ $^ -shared $(LDFLAGS)
	$(STRIP) $@
else
	$(AR) rc $@ $^
endif

%.o:%.c
	$(CC) $(CFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

%.o:%.cpp
	$(CXX) $(CXXFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

install:
	test -d $(INS_DIR) || install -m 755 -d $(LIBDIR)
	install -m 755 $(TARGET) $(INS_DIR)

clean:
	-rm -rf $(OBJS) *.d $(TARGET)

.PHONY: all clean install
	
	